<?php

namespace app\common\model;
use think\Model;

class City extends Model
{
    protected  $autoWriteTimestamp = true;

    public function add($data)
    {
        $data['status']=1;
        return $this->save($data);
    }

    function getCitysByStatus($status){
        $data=[
            'status'=>$status,
        ];
        $order=[
            'id'=>'desc',
        ];
        $result=$this->where($data)->order($order)->paginate();
        return $result;
    }
    public function getFirstCitys($parentId=0)
    {
        $data=[
            'parent_id'=>$parentId,
            'status'=>['neq',-1],
        ];
        $order=[
            'listorder' =>'desc',
            'id'=>'desc',
        ];
        $result=$this->where($data)->order($order)->paginate();
        return $result;
    }

    public function getNormalFirstCity()
    {
        $data=[
            'status'=>1,
            'parent_id'=>0,
        ];
        $order=[
            'id'=>'desc',
        ];
        return $this->where($data)->order($order)->select();
    }

    public function getNormalCitysByParentId($parentId=0) {
        $data = [
            'status' => 1,
            'parent_id' => $parentId,
        ];

        $order = [
            'id' => 'desc',
        ];

        return $this->where($data)
            ->order($order)
            ->select();
    }

    public function getNormalCitys() {
        $data = [
            'status' => 1,
            'parent_id' => ['gt', 0],
        ];

        $order = ['id'=>'desc'];

        return $this->where($data)
            ->order($order)
            ->select();

    }
}